package com.example.administrator.hero.fragments;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.administrator.hero.R;
import com.example.administrator.hero.adapter.VpAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * A simple {@link Fragment} subclass.
 */
public class RideoFragment extends Fragment {


    private TabLayout tab;
    private ViewPager vp;
    private List<Fragment> fragments;

    public RideoFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        return inflater.inflate(R.layout.fragment_rideo, container, false);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        fragments = new ArrayList<>();
        tab = (TabLayout) view.findViewById(R.id.tab);
        vp = (ViewPager) view.findViewById(R.id.vp);
        initData();
        VpAdapter adapter = new VpAdapter(getActivity().getSupportFragmentManager(), fragments);
        tab.setTabsFromPagerAdapter(adapter);
        vp.setAdapter(adapter);
        tab.setupWithViewPager(vp);
    }

    private void initData() {
        fragments.add(new HomeFragment());
        fragments.add(new ConsultFragment());
    }
}
